package com.sinosoft.dsp.builder.velocity;

import java.io.InputStream;

import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.Resource;

/**
 * 
 * @author 潘巍（Peter Pan）
 * @since 2010-8-4 下午05:50:53
 */
public class ResourceLoader extends
		org.apache.velocity.runtime.resource.loader.ResourceLoader {

	public void init(ExtendedProperties configuration) {
		rsvc.info("ClasspathResourceLoader : 初始化开始...");

		rsvc.info("ClasspathResourceLoader : 初始化完成...");
	}

	public synchronized InputStream getResourceStream(String name)
			throws ResourceNotFoundException {
		InputStream result = null;

		if (name == null || name.length() == 0) {
			throw new ResourceNotFoundException("没有找到指定名称的模板");
		}

		try {
			ClassLoader classLoader = getClass().getClassLoader();

			result = classLoader.getResourceAsStream(name);
		} catch (Exception fnfe) {
			throw new ResourceNotFoundException(fnfe.getMessage());
		}

		return result;
	}

	public boolean isSourceModified(Resource resource) {
		return false;
	}

	public long getLastModified(Resource resource) {
		return 0;
	}
}
